package com.example.musicwebcon.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//MVC配置类  配置静态资源映射（如图片、CSS、JS 文件的访问路径）。
// 具体来说，上述代码的作用是将 URL 路径 /uploads/** 映射到项目的 src/main/resources/uploads 目录。
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 将 /uploads/** 映射到应用根目录的 uploads 文件夹
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + System.getProperty("user.dir") + "/uploads/");
        registry.addResourceHandler("/uploads/songlists/**")
                .addResourceLocations("file:" + System.getProperty("user.dir") + "/uploads/songlists/");
    }

}
